Skip to main content
Version: 6.1.0

create.js

create.js is configuration of JavaScript logic when trigger is created.

It will be executed when user creates a webhook for subscription/automation.

With input variable, user can create their own logic for trigger.

You need to put a service api call logic to register a new webhook trigger.

Expected input/output

  • Execution input
    • automation_id
      • identifier for automation(subscription)
    • user_id
      • user id
    • variable
      • trigger variables
    • webhook_url
      • webhook url for registration
    • lifecycle_url
      • lifecycle url for handling lifecycle notification
  • Execution output
    • output
      • data for trigger execution
      • customizable type
    • target
      • data for webhook type target
    • subscription_id
      • subscription id to identify subscription

Example create.js

try {

const folderResponse = await $.axios({
method: "get",
url: `https://graph.microsoft.com/v1.0/me/mailFolders/SentItems`,
headers: {
"Authorization": `Bearer ${service.token}`,
"Content-Type": "application/json"
}
})
const folderId = folderResponse.data.id

const date = new Date();
const expirationDateTime = new Date(date.setMinutes(date.getMinutes() + 4230)).toISOString();
const body = {
"changeType": "updated",
"expirationDateTime": expirationDateTime,
"notificationUrl": input.webhook_url,
"resource": `me/mailFolders('${folderId}')/messages`,
"lifecycleNotificationUrl": input.lifecycle_url,
"clientState": input.automation_id
}

const response = await $.axios({
method: "post",
url: `https://graph.microsoft.com/v1.0/subscriptions`,
headers: {
"Authorization": `Bearer ${service.token}`,
"Content-Type": "application/json"
},
data: body
})

return {
"output": {
id: response.data.id,
resource: response.data.resource
},
"subscription_id": response.data.id,
"target": input.automation_id
}

} catch (error) {
throw error
}